package org.teremail;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import javax.sql.DataSource;

public abstract class AbstractDBConfig implements DBConfig {

    private final FutureTask<DataSource> instance = 
        new FutureTask<DataSource>(new Callable<DataSource>() {

            public DataSource call() throws Exception {
                return loadDS();
            }
            
        });
    
    public final DataSource getDataSource() {
        instance.run();
        try {
            return instance.get();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    protected abstract DataSource loadDS();
}
